<?php
namespace app\modules\controllers;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use app\models\Order;

class OrderController extends Controller
{
    public function actionList()
    {
        $this->layout="adminlist.php";
        $model= Order::find();
        $count=$model->count();
        $pageSize= \Yii::$app->params['pageSize']['order'];//从配置文件中获取
        $pager=new Pagination(['totalCount'=>$count,'pageSize'=>$pageSize]);
        $orders=$model->offset($pager->offset)->limit($pager->limit)->all();
        $ordersDetaol= Order::getDetail($orders);
        return $this->render('orders',['orders'=>$ordersDetaol,'pager'=>$pager]);
    }
    
    public function actionDetail()
    {
        $this->layout="adminlist.php";
        $orderid= (int)Yii::$app->request->get('orderid');
        $order= Order::find()->where('orderid=:oid',[':oid'=>$orderid])->one();
        $data=Order::getOrder($order);
        return $this->render('detail',['order'=>$data]);
    }
    
    public function actionSend()
    {
        $this->layout="adminlist.php";
        $orderid= Yii::$app->request->get('orderid');
        $model=Order::find()->where('orderid=:oid',[':oid'=>$orderid])->one();
        $model->scenario='send';
        if(Yii::$app->request->isPost){
            $post= Yii::$app->request->post();
            $model->status= Order::SENDED;
            if($model->load($post) && $model->save()){
                Yii::$app->session->setFlash('info','发货成功');
            }
        }
        return $this->render('send',['model'=>$model]);
    }
}